package STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.View;

import java.util.Scanner;

import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Controller.Controllers;
import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Entity.Books;
import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Entity.Guests;

public class Views {
	private static Scanner sc = new Scanner(System.in);

	private static void showMenu() {
		System.out.println("Nhap lua chon: ");
		System.out.println("1.Add book");
		System.out.println("2.List book");
		System.out.println("3.Add Guest");
		System.out.println("4.List Guest");
		System.out.println("5. Borrow Book");
		System.out.println("6. Show Borrow");
		System.out.println("7.Exit");
		System.out.println("Chon tu 1-7");
	}

	private static Books input() {
		int bookID, bookYear;
		String bookName, bookAuthor;
		String[] kindArr = { "Khoa học tự nhiên", "Văn học - Nghệ thuật", "Điện tử viễn thông", "Công nghệ thông tin" };
		System.out.println("ID: ");
		sc = new Scanner(System.in);
		bookID = sc.nextInt();

		System.out.println("Name: ");
		sc = new Scanner(System.in);
		bookName = sc.nextLine();

		System.out.println("Year: ");
		sc = new Scanner(System.in);
		bookYear = sc.nextInt();

		System.out.println("Author: ");
		sc = new Scanner(System.in);
		bookAuthor = sc.nextLine();

		System.out.println("Kind of Book: 0-Khoa học tự nhiên. 1-Văn học - Nghệ thuật. "
				+ "2-Điện tử viễn thông 3-Công nghệ thông tin");
		sc = new Scanner(System.in);
		int i = sc.nextInt();

		Books bookObj = new Books(bookName, bookAuthor, kindArr[i], bookID, bookYear);

		return bookObj;

	}

	public static Guests input2() {
		int guestID, guestPN;
		String guestName, guestAdr;
		String[] jobARR = { "Sinh Viên", "Cao Học Viên", "Giảng Viên" };

		System.out.println("ID: ");
		sc = new Scanner(System.in);
		guestID = sc.nextInt();
		System.out.println("Name: ");
		sc = new Scanner(System.in);
		guestName = sc.nextLine();
		System.out.println("Phone Number: ");
		guestPN = sc.nextInt();
		System.out.println("Address: ");
		sc = new Scanner(System.in);
		guestAdr = sc.nextLine();
		System.out.println("Kind of Book: 0-Sinh Viên. 1-Cao Học Viên. 2-Giảng Viên");
		int i = sc.nextInt();

		Guests guestObj = new Guests(guestName, guestAdr, jobARR[i], guestID, guestPN);
		return guestObj;
	}

	public static String findBook() {
		String bookName;

		System.out.println("Book Name");
		sc = new Scanner(System.in);
		bookName = sc.nextLine();

		return bookName;
	}

	public static String findGuest() {
		String guestName;

		System.out.println("Guest Name");
		sc = new Scanner(System.in);
		guestName = sc.nextLine();

		return guestName;
	}

	public static void main(String[] args) {
		Controllers ctrObj = new Controllers();

		int functionID = 0;
		boolean flag = true;

		do {
			showMenu();

			try {
				sc = new Scanner(System.in);
				functionID = sc.nextInt();

				switch (functionID) {
				case 1:
					ctrObj.checkInput(input());
					break;
				case 2:
					ctrObj.checkOutput();
					break;
				case 3:
					ctrObj.checkInputGuest(input2());
					break;
				case 4:
					ctrObj.checkOutputGuest();
					break;
				case 5:
					ctrObj.checkBorrow(findBook(), findGuest());
					break;
				case 6:
					ctrObj.showBorrow();
				case 7:
				default:
					flag = false;
					break;
				}

			} catch (Exception e) {
				System.out.println("Error! Please try again!");
				flag = true;
			}

		} while (flag == true);

	}

}
